package com.auto.autoapp.ui.mine

import android.annotation.SuppressLint
import android.content.Intent
import android.view.View
import com.auto.autoapp.base.BaseFragment
import com.auto.autoapp.databinding.FragmentMineBinding
import com.auto.autoapp.ui.activity.CommonSettingActivity
import com.auto.autoapp.ui.activity.LoginActivity
import com.auto.autoapp.util.SpUtil
import com.auto.autoapp.widgets.SimpleToolbar
import com.kongzue.dialogx.DialogX
import com.kongzue.dialogx.dialogs.MessageDialog
import com.kongzue.dialogx.interfaces.OnDialogButtonClickListener
import com.ven.assists.AssistsCore
import com.ven.assists.stepper.StepManager

class MineFragment : BaseFragment() {
    companion object Companion {
        fun newInstance(): MineFragment {
            return MineFragment()
        }
    }

    private lateinit var _binding: FragmentMineBinding

    override fun configToolbar(toolbar: SimpleToolbar) {
        toolbar.setTitle("我的")
        toolbar.hideBack()
    }

    @SuppressLint("SetTextI18n")
    override fun onInit() {
        _binding.tvNickname.text = "昵称：${SpUtil.getUserAccount() ?: ""}"
        _binding.tvMembershipExpiry.text = "到期时间：-"
        val logoutListener = object : OnDialogButtonClickListener<MessageDialog> {
            override fun onClick(dialog: MessageDialog?, v: View?): Boolean {
                SpUtil.clear()
                StepManager.isStop = true
                startActivity(Intent(requireContext(), LoginActivity::class.java).apply {
                    addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
                })
                return false
            }
        }
        _binding.svLogout.setOnClickListener {
            MessageDialog.build().setTitle("提示").setMessage("是否退出登录？")
                .setCancelButton("取消")
                .setOkButton("确定")
                .setOkButtonClickListener(logoutListener).show()
        }
        _binding.svCommonSetting.setOnClickListener {
            startActivity(Intent(requireContext(), CommonSettingActivity::class.java))
        }
    }

    override fun provideView(): View {
        _binding = FragmentMineBinding.inflate(layoutInflater)
        return _binding.root
    }


}